# -*- coding: utf-8 -*-
'''
@文件    :wxPay.py
@说明    :合利宝微信支付相关接口
@时间    :2025/08/02 15:05:23
@作者    :浪晋
@版本    :1.0
'''


from . import base
from .. import utils

class WxPayClient(base.BaseClient):


    def unified_order(self, merchantNo, order_id, app_id, openid, amount, notifyUrl, desc, ip, **kwargs):
        """JSAPI/小程序下单"""
        url = self.base_url + "/trx/app/interface.action"
        headers = {
            "Content-Type":"application/x-www-form-urlencoded;charset=utf-8"
        }
        body = {
            "P2_orderId": order_id,
            "P3_customerNumber": merchantNo,
            "P4_payType": "PUBLIC",
            "P5_appid": app_id,
            "P6_deviceInfo": "WEB",
            "P7_isRaw": "1",
            "P8_openid": openid,
            "P9_orderAmount": amount, # 单位分
            "P10_currency": "CNY",
            "P11_appType": "WXPAY",
            "P12_notifyUrl": notifyUrl,
            "P13_successToUrl":"",
            "P14_orderIp": ip,
            "P15_goodsName": desc,
            "P16_goodsDetail":"",
            "P17_limitCreditPay": "0",
            "P18_desc": "" # 备注原样返回
        }
        body.update(kwargs)  # 添加额外的参数
        data = self._build_common_data('AppPayPublic', body)
        return self._request(url, headers=headers, data=data, verified="sign")
    